package com.mall.web.controller.course.admin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.mall.course.courseCategory.domain.dto.CourseCategoryDto;
import com.mall.course.courseCategory.domain.vo.CourseCategoryVo;
import com.mall.course.courseCategory.service.ICourseCategoryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.enums.BusinessType;
import com.mall.common.utils.poi.ExcelUtil;

/**
 * 课程分类Controller
 *
 * @author mall
 * @date 2024-05-17
 */
@RestController
@RequestMapping("/admin/course/courseCategory")
public class CourseCategoryController extends BaseController
{
    @Autowired
    private ICourseCategoryService courseCategoryService;

    /**
     * 查询课程分类列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseCategory:list')")
    @GetMapping("/list")
    public AjaxResult list(CourseCategoryDto courseCategoryDto)
    {
        List<CourseCategoryVo> list = courseCategoryService.selectCourseCategoryList(courseCategoryDto);
        return success(list);
    }

    /**
     * 导出课程分类列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseCategory:export')")
    @Log(title = "课程分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseCategoryDto courseCategoryDto)
    {
        List<CourseCategoryVo> list = courseCategoryService.selectCourseCategoryList(courseCategoryDto);
        ExcelUtil<CourseCategoryVo> util = new ExcelUtil<CourseCategoryVo>(CourseCategoryVo.class);
        util.exportExcel(response, list, "课程分类数据");
    }

    /**
     * 获取课程分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:courseCategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(courseCategoryService.selectCourseCategoryById(id));
    }

    /**
     * 新增课程分类
     */
    @PreAuthorize("@ss.hasPermi('course:courseCategory:add')")
    @Log(title = "课程分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseCategoryDto courseCategoryDto)
    {
        return toAjax(courseCategoryService.insertCourseCategory(courseCategoryDto));
    }

    /**
     * 修改课程分类
     */
    @PreAuthorize("@ss.hasPermi('course:courseCategory:edit')")
    @Log(title = "课程分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseCategoryDto courseCategoryDto)
    {
        return toAjax(courseCategoryService.updateCourseCategory(courseCategoryDto));
    }

    /**
     * 删除课程分类
     */
    @PreAuthorize("@ss.hasPermi('course:courseCategory:remove')")
    @Log(title = "课程分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(courseCategoryService.deleteCourseCategoryByIds(ids));
    }
}
